package cn.tedu.mall.seckill.config;

import cn.tedu.mall.seckill.timer.InitSeckillJob;
import cn.tedu.mall.seckill.timer.SeckillBloomInit;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class InitSeckillConfig {
    //定义JobDetail
    @Bean
    public JobDetail initSeckillJobDetail(){
        return JobBuilder.newJob(InitSeckillJob.class)
                .withIdentity("initSeckillJobDetail")
                .storeDurably()
                .build();
    }
    //定义Trigger
    @Bean
    public Trigger initSeckillTrigger(){
        //定义表达式
        CronScheduleBuilder cron = CronScheduleBuilder.cronSchedule("0 0/1 * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(initSeckillJobDetail())
                .withIdentity("initSeckillTrigger")
                .withSchedule(cron)
                .build();
    }
    //定义布隆过滤器的JobDetail
    @Bean
    public JobDetail initBloomJobDetail(){
        return JobBuilder.newJob(SeckillBloomInit.class)
                .withIdentity("initBloomJobDetail")
                .storeDurably()
                .build();
    }
    //定义布隆过滤器的Trigger
    @Bean
    public Trigger initBloomTrigger(){
        //定义表达式
        CronScheduleBuilder cron = CronScheduleBuilder.cronSchedule("* * * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(initBloomJobDetail())
                .withIdentity("initBloomTrigger")
                .withSchedule(cron)
                .build();
    }
}
